{if !$addnew}
    [ <a href="index.php?p=view&ID={$entryID}">View</a> ]
    {if $user_admin}
    [ <a style="color: #f00;" href="index.php?p=delete&ID={$entryID}">Delete</a> ]
    {/if}
{/if}


<div id="addtabs"> 


{if $addnew}
  <ul> 
			<li><a href="#etbibtex" style="font-size: x-small;">Bibtex</a></li>
	{section name=entrytypes loop=$fields}
			<li><a href="#et{$fields[entrytypes].name}" style="font-size: x-small;">{$fields[entrytypes].name|capitalize}</a></li>
	{/section}
  </ul> 
    <div id="etbibtex" class="addtabcontent">
        <form method="post" action="index.php" style="display: inline;" class="entryform" id="formbibtex">  
            <div id="bibteximport">
            Copy and paste a single BibTeX or Reference entry below.<br />
            <textarea name="bibteximport" style="background-color: rgb(220,230,255); width: 100%; height: 200px;">{$bibImport}</textarea>
            <input type="submit" class="submit" value="Import" />
            </div>
    		<input type="hidden" name="p" value="{$page}" />
			<input type="hidden" class="entrytype" name="entrytype" value="bibtex" />
        </form>
    </div>
{/if}

{section name=entrytypes loop=$fields}
  <div id="et{$fields[entrytypes].name}" class="addtabcontent">
	<form enctype="multipart/form-data" method="post" action="index.php" style="display: inline;" class="entryform" id="form{$fields[entrytypes].name}">  
	

        {include file="metadata.tpl"}		
	
		
		{if !$addnew}
    		<input type="hidden" name="ID" value="{$entryID}" />
        {/if}				
        {if isset($duplicate)}
    		<input type="hidden" name="ignoreDuplicate" value="1" />
        {/if}				        
    		<input type="hidden" name="p" value="{$page}" />
	
	
  	<table style="margin-left: auto; margin-right: auto; width: 100%;">
		<tr><td colspan="3"><h1>Required Fields</h1></td></tr>
		
		{if !$addnew}
		<tr><th>Entry&nbsp;Type</th>
		<td>{html_options name=entrytype output=$types|capitalize values=$types selected=$fields[entrytypes].name}</td>
		<td>&nbsp;</td>
		</tr>
		{else}
			<input type="hidden" class="entrytype" name="entrytype" value="{$fields[entrytypes].name}" />
		{/if}
		
		<tr>
			<th>Entry&nbsp;Key</th>
			<td width="100%"><input type="text" name="field_entrykey" value="{$values.entrykey}" /><div id="uniquekeycheck"></div></td>
			<td>
				 <a id="entrykeytip_{$fields[entrytypes].name}" href="$entrykeyTip?width=300" class="betterTip" title="Entry Key Notes">?</a>
			</td>
		</tr>
		
		
		{section name=req loop=$fields[entrytypes].req}
			{assign var='val' value=$fields[entrytypes].req[req]}
			<tr>
				<th>{$val|capitalize}</th>
			    {if $val != "title"}
			    <td width="100%"><input type="text" name="field_{$val}" id="field_{$fields[entrytypes].name}_{$val}" value="{$values.$val}" /></td>
{else}
			    <td width="100%"><textarea type="text" name="field_{$val}" style="width: 100%;" rows="4" id="field_{$fields[entrytypes].name}_{$val}">{$values.$val}</textarea></td>
{/if}

			    {if $val == "author"}
			    <td>
					 <a id="authortip_{$fields[entrytypes].name}" href="$authorTip?width=400" class="betterTip" title="Author Example">?</a>
			    </td>
			    {else}
				    <td>&nbsp;</td>
				{/if}
				
				{if $val == "author" || $val == "journal"}
                    {literal}
                    <script type="text/javascript"> 
                    $(function() {	
                        $("#{/literal}field_{$fields[entrytypes].name}_{$val}{literal}").autocomplete("autocomplete.php?t=field&f={/literal}{$val}{literal}", 
                                { minChars:3, matchSubset:1, matchContains:1, cacheLength:10, selectOnly:1, width:'300' });
                    });
                    </script>
                    {/literal}				
				{/if}
				
			</tr>
		{/section}
		<tr><td colspan="3" align="center"><input type="submit" class="submit" value="Save {$fields[entrytypes].name|capitalize}" /></td></tr>						
		<tr><td colspan="3"><h1>Optional Fields</h1></td></tr>
		{section name=opt loop=$fields[entrytypes].opt}
			{assign var='val' value=$fields[entrytypes].opt[opt]}
		
			<tr>
				<th>{$val|capitalize}</th>
			    <td width="100%"><input type="text" name="field_{$val}" value="{$values.$val}" /></td>
			    {if $val == "pages"}
			    <td>
					 <a id="pagestip_{$fields[entrytypes].name}" href="$pagesTip?width=200" class="betterTip" title="Pages Example">?</a>
			    </td>
			    {else}
				    <td>&nbsp;</td>
				{/if}
			</tr>
		{/section}		
		<tr><td colspan="3" align="center"><input type="submit" class="submit" value="Save {$fields[entrytypes].name|capitalize}" /></td></tr>						
		<tr><td colspan="3"><h1>File Upload</h1></td></tr>		
		<tr><td colspan="2">
        {if $uploads_perm_fail}
        <div class="error">Unable to write to <strong>uploads</strong> folder. Please change permissions to ensure your webserver can write to this folder. Files can not be uploaded until this is fixed.</div>    
        {else}
		{if $tmpfile}
		<div class="metadatabox" style="font-size: x-small; padding: 2px;"><strong>Uploaded: </strong>{$tmpfile} [<input type="checkbox" id="deleteUpload" name="deleteUpload" value="1" /><label for="deleteUpload" style="font-weight: bold; color: #f00;">Check Here to Delete Upload</label>]<br /><span style="font-size: x-small;">File will be replaced if a new file is uploaded.</span><br />Preview page {html_options name=previewPage options=$previewPages selected=$previewPage}<input type="hidden" name="oldPreviewPage" value="{$previewPage}" /></div>
        {/if}
		<input type="file" name="file" /></td>
        {/if}
		<td><a id="pagestip_{$fields[entrytypes].file}" href="$fileTip?width=200" class="betterTip" title="File Upload">?</a></td></tr>
		
		
		<tr><td colspan="3"><h1>Abstract</h1></td></tr>		
		<tr><td colspan="3">
		<textarea name="field_abstract" style="width: 96%;" rows="15">{$values.abstract}</textarea>
		</td></tr>
		<tr><td colspan="3" align="center"><input type="submit" class="submit" value="Save {$fields[entrytypes].name|capitalize}" /></td></tr>								
        </table>










	</form>
  </div> 
{/section}

</div> 

{if $addnew}
{literal}
<script type="text/javascript"> 
 $(function () {
      $("#addtabs").tabs();
    }
  );  
</script>
{/literal}
{/if}

{if isset($duplicate)}
{literal}
<script type="text/javascript"> 

var ignoreDuplicate = 0;

 $(function () {
      $("form.entryform").submit( function() { 
        
        if (ignoreDuplicate == 1)
        {
            return true;
        }

       id = $(this).attr("id");
       $.prompt('Are you sure this entry isn\'t a duplicate of <br />{/literal}{$duplicate}{literal}<br />?<input type="hidden" id="formID" name="formID" value="#'+id+'" />',
       {
        buttons:{'Add Item':'add', 'Edit Item':'edit', 'Clear Item':'clear'},
        prefix:'colsJqi',
        show:'slideDown',
        callback: processDuplicatePrompt
       }
       );
       return false;
      }); 
    }
  );  

function processDuplicatePrompt(v,m) {
    switch(v)
    {
        case 'add':
            ignoreDuplicate = 1;
            $(m.children('#formID').val()).submit();
        break;
        
        case 'edit':
            // Do nothing.  Just close the prompt.
            return true;
        break;
        
        case 'clear':
        break;
    }
}
  
</script>
{/literal}
{/if}



<div id="authorTip" style="display:none;">
	Piccard, Sophie and Newton, Issac and Wiles, Andrew J.
</div>			    
<div id="pagesTip" style="display:none;">
123--135 <em>(Note double --)</em>
</div>			    
<div id="entrykeyTip" style="display:none;">
Used to reference your entry in LaTeX.<br />
Must be unique within IRIS.<br />
Example: <em>smithetal94</em>
</div>			    
<div id="fileTip" style="display:none;">
